
import React from 'react';
import { useAuth } from '@/hooks/useAuth';

export const hasPermission = (requiredPermissions: string[]): boolean => {
  const { userInfo } = useAuth();
  if (!userInfo || !userInfo.perms) return false;
  return requiredPermissions.some(perm => userInfo.perms.includes(perm));
};

export const PermissionButton: React.FC<{
  permissions: string[];
  children: React.ReactNode;
}> = ({ permissions, children }) => {
  const hasAccess = hasPermission(permissions);
  return hasAccess ? <>{children}</> : null;
};
